package com.xzx.shop_front_api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.xzx.shop_front_api.entity.Coupon;
import com.xzx.shop_front_api.entity.MemberCoupon;
import com.xzx.shop_front_api.mapper.CouponMapper;
import com.xzx.shop_front_api.mapper.MemberCouponMapper;
import com.xzx.shop_front_api.service.CouponService;
import com.xzx.shop_front_api.service.MemberCouponService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MemberCouponServiceImpl implements MemberCouponService {


    @Autowired
    private MemberCouponMapper memberCouponMapper;
    @Override
    public int getCoupon(MemberCoupon memberCoupon) {
        return memberCouponMapper.insert(memberCoupon);
    }

    @Override
    public MemberCoupon getCouponInfoByMemberIdCouponId(int memberId, int couponId) {
        QueryWrapper<MemberCoupon> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("member_id", memberId);
        queryWrapper.eq("coupon_id", couponId);
        return memberCouponMapper.selectOne(queryWrapper);
    }

    @Override
    public List<MemberCoupon> getCouponInfoByMemberId(int memberId) {
        QueryWrapper<MemberCoupon> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("member_id", memberId);
        return memberCouponMapper.selectList(queryWrapper);
    }

    @Override
    public List<MemberCoupon> canUseCouponList(int memberId, int status) {
        QueryWrapper<MemberCoupon> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("member_id", memberId);
        queryWrapper.eq("status", status);
        return memberCouponMapper.selectList(queryWrapper);
    }
}
